package cn.org.timespace.easyframe.service.permission.impl;

import java.util.List;

import cn.org.timespace.easyframe.action.permission.EFRoleModel;
import cn.org.timespace.easyframe.dao.permission.EfRoleDAO;
import cn.org.timespace.easyframe.dao.permission.EfRoleMenuDAO;
import cn.org.timespace.easyframe.dao.permission.EfRoleMenuShortcutDAO;
import cn.org.timespace.easyframe.dao.permission.EfUserRoleDao;
import cn.org.timespace.easyframe.model.permission.EfRole;
import cn.org.timespace.easyframe.model.permission.EfRoleShortcutmenu;
import cn.org.timespace.easyframe.service.permission.EfRoleService;
import cn.org.timespace.easyframe.util.generator.IdentityGenerator;

public class EfRoleServiceImpl implements EfRoleService {
	// property constants
	public static final String ROLE_NAME = "roleName";
	public static final String ROLE_CODE = "roleCode";
	public static final String DIC_ROLE_IS_VALID = "dicRoleIsValid";

	private EfRoleDAO efRoleDao;
	
	private EfRoleMenuDAO efRoleMenuDao;
	 
	private EfRoleMenuShortcutDAO efRoleMenuShortcutDao;
	
	private EfUserRoleDao efUserRoleDao;

	public EfRoleDAO getEfRoleDao() {
		return efRoleDao;
	}

	public void setEfRoleDao(EfRoleDAO efRoleDao) {
		this.efRoleDao = efRoleDao;
	}

	public EfRoleMenuShortcutDAO getEfRoleMenuShortcutDao() {
		return efRoleMenuShortcutDao;
	}

	public void setEfRoleMenuShortcutDao(EfRoleMenuShortcutDAO efRoleMenuShortcutDao) {
		this.efRoleMenuShortcutDao = efRoleMenuShortcutDao;
	}

	public EfRoleMenuDAO getEfRoleMenuDao() {
		return efRoleMenuDao;
	}

	public void setEfRoleMenuDao(EfRoleMenuDAO efRoleMenuDao) {
		this.efRoleMenuDao = efRoleMenuDao;
	}

	public EfUserRoleDao getEfUserRoleDao() {
		return efUserRoleDao;
	}

	public void setEfUserRoleDao(EfUserRoleDao efUserRoleDao) {
		this.efUserRoleDao = efUserRoleDao;
	}

	public void save(EfRole transientInstance) {
		transientInstance.setRoleId(IdentityGenerator.getInstance().getId());
		efRoleDao.save(transientInstance);
	}

	public void delete(EfRole persistentInstance) {
		efRoleDao.delete(persistentInstance);
	}
	
	public void deleteRole(String roleId) {
		
		List<EfRoleShortcutmenu> list=efRoleMenuShortcutDao.findEfRoleShortcutmenuByRoleId(roleId);
		for(EfRoleShortcutmenu roleShortcutmenu:list){
			efRoleMenuShortcutDao.delete(roleShortcutmenu);
		}
		efRoleMenuDao.delete(roleId);
		efUserRoleDao.delete(roleId);
		efRoleDao.delete(roleId);
	}

	public EfRole findById(String roleId) {
		return efRoleDao.findById(roleId);
	}

	public List<EfRole> findByCondition(EFRoleModel model) {
		return efRoleDao.findByCondition(model);
	}

	public void update(EfRole transientInstance) {
		efRoleDao.update(transientInstance);
	}
}